<?php


if(isset($_GET['key']) && isset($_GET['id'])){
	$key = $_GET['key'];
	$id = $_GET['id'];
	
	include 'func/addPar.php';
	include 'func/sql.php';
	include 'func/check.php';
	include 'func/get.php';
	include 'func/mail.php';
	include 'func/layout.php';
	include 'admin/adminfunc.php';
	include 'admin/delete.php';
	
	settype($key,"string");
	settype($id,"integer");
	$wl = false;
	
	if(isset($_GET['wl'])){
		$wl = true;
	}
	
	if($wl){
		$sql = sprintf("SELECT * FROM event_%s_waitlist WHERE mkey = '%s';", $id, $key);
	}else{
		$sql = sprintf("SELECT * FROM event_%s WHERE mkey = '%s';", $id, $key);
	}
	$res = sendQ($sql);
	$resA = mysql_fetch_array($res);
	
	$name = $resA['name'];
	$paidStatus = 0;
	if(!$wl){
		$paidStatus = $resA['paidStatus'];
	}
	$res = sendQ(sprintf("SELECT name FROM events WHERE ID = %s;",$id));
	$event = mysql_fetch_array($res);
	$event = $event['name'];
	if($wl){
		$sql = sprintf("DELETE FROM event_%s_waitlist WHERE mkey = '%s';", $id, $key);
	}else{
		$sql = sprintf("DELETE FROM event_%s WHERE mkey = '%s';", $id, $key);
	}
	
	$res = sendQ($sql);
	
	if($res){
		//SUCCES
		if(!isWLEmpty($id)){
			$ns = newSpot($id);
		}
	}else{
		//SOMETHING WENT WRONG...
	}
	

			
	$msg = "<h1>Meddelelse</h1><p><b>". $name . "</b> har frameldt sig eventet <b>" . $event . "</b>!</p>";
	if($paidStatus){
		$msg .= "<h3>!!!! Deltageren har betalt!!!!</h3>";
	}else{
		$msg .= "<h3>!!!! Deltageren har <u>ikke</u> betalt !!!!</h3>";
	}
	//sendMail("web@sofa-it.dk",$msg,"System meddelelse: Slettet deltager");
	getHeader();
	echo '<div id="content">';
	echo '<h2>Du er nu blevet fjernet</h2>';
	echo '<a href="http://sofa-it.dk/" id="submitbutton">Tilbage</a>';
	echo '</div>';
	getBackTo();
	getCopyr();
	echo 	'</div></div>' .
			'<div id="botgradient"></div>
		</body>
		</html>';

}else{
	header('Location: index.php');
}

?>